package StudyCode.summary.mycollection;

import java.lang.reflect.Array;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertListOfArraysOfObjectsToArrayOfArraysOfObjects {
	public static void main(String[] argv) {
		List list = java.util.Arrays.asList("asdf", "www.tah1986.com");
		Class arrayElements = String.class;
		System.out.println(java.util.Arrays
				.toString(listOfArraysToDoubleArray(list, arrayElements)));
	}

	@SuppressWarnings("unchecked")
	public static <T> T[][] listOfArraysToDoubleArray(List<T[]> list,
	                                                  Class<T> arrayElements) {
		T[][] result = (T[][]) Array.newInstance(arrayElements, new int[]{
				list.size(), 0});
		int i = 0;
		for (T[] array : list) {
			result[i++] = array;
		}
		return result;
	}
}
